package org.syntaxlisp.core.match.tree;

import org.syntaxlisp.core.utils.ListTreeMap;

import java.util.HashMap;
import java.util.Map;

/**
 * @author HuangYijun
 * @data 2024-02-08 15:49
 **/
public class CursorMatchHistory {

    /**
     * def start -> cur offset -> next offset -> match state : ListTreeMap<RepeatFrame, Boolean>
     */
    private Map<Integer,
                Map<Integer,
                    Map<Integer,
                        Map<MatchState, ListTreeMap<RepeatFrame, Boolean>>>>> cursorMatchHistoryMap;

    public CursorMatchHistory () {
        cursorMatchHistoryMap = new HashMap<>();
    }

    public boolean put (PureCursor pureCursor) {
        return cursorMatchHistoryMap.computeIfAbsent(pureCursor.getDefStart(), defStart -> new HashMap<>())
                                    .computeIfAbsent(pureCursor.getCurOffset(), curOffset -> new HashMap<>())
                                    .computeIfAbsent(pureCursor.getNextOffset(), nextOffset -> new HashMap<>())
                                    .computeIfAbsent(pureCursor.getCurState(), state -> new ListTreeMap<>())
                                    .put(pureCursor.getRepeatStackLastNode(), true);
    }
}
